{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "current-avatar",
   "metadata": {},
   "source": [
    "# Problem 14.15 Joule-Thomson Coefficient for Methane Using the Peng-Robinson EOS"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "acting-welcome",
   "metadata": {},
   "source": [
    "Calculate the Joule-Thomson coefficient of methane at 300 K and 30 bar, using the Peng Robinson model.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "preceding-corpus",
   "metadata": {},
   "source": [
    "## Solution\n",
    "\n",
    "This is straightforward."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "sufficient-central",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The JT coefficient at the specified conditions is 4.644e-06 K/Pa\n"
     ]
    }
   ],
   "source": [
    "# Set the conditions and imports\n",
    "from scipy.constants import bar\n",
    "from thermo import ChemicalConstantsPackage, PRMIX, CEOSLiquid, CEOSGas, FlashPureVLS\n",
    "fluid = 'methane'\n",
    "constants, correlations = ChemicalConstantsPackage.from_IDs([fluid])\n",
    "\n",
    "T = 300\n",
    "P = 30*bar\n",
    "zs = [1]\n",
    "\n",
    "eos_kwargs = dict(Tcs=constants.Tcs, Pcs=constants.Pcs, omegas=constants.omegas)\n",
    "liquid = CEOSLiquid(PRMIX, HeatCapacityGases=correlations.HeatCapacityGases,\n",
    "                    eos_kwargs=eos_kwargs)\n",
    "gas = CEOSGas(PRMIX, HeatCapacityGases=correlations.HeatCapacityGases, \n",
    "              eos_kwargs=eos_kwargs)\n",
    "flasher = FlashPureVLS(constants, correlations, liquids=[liquid], gas=gas, solids=[])\n",
    "\n",
    "res = flasher.flash(T=T, P=P, zs=zs)\n",
    "print(f'The JT coefficient at the specified conditions is {res.Joule_Thomson():.4g} K/Pa')"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
